@extends('layouts.default')

@section('title')
    {{{ $topic->title }}} | @parent
@stop

@section('description')
    {{{ $topic->excerpt }}}
@stop

{{--@section('wechat_icon')--}}
{{--@if ($cover = $topic->cover())--}}
{{--<img src="{{ img_crop($cover->link, 512, 512) }}" alt="">--}}
{{--@else--}}
{{--@parent--}}
{{--@endif--}}
{{--@stop--}}

@section('content')

    <div class="col-md-10 topics-show main-col">
        <!-- Topic Detial -->
        <div class="topic panel panel-default">
            <div class="infos panel-heading">
                <h1 class="panel-title topic-title">
                    {{{ $topic->title }}}
                </h1>
                @include('topics.partials.meta')
            </div>

            <div class="content-body entry-content panel-body ">
                <div class="markdown-body" id="emojify">
                    <blockquote><p>这是一篇协同翻译</p></blockquote>
                </div>
                @foreach($topic->translateSections as $section)

                        @if($section->is_translated == \App\Models\TranslateSection::IS_TRANSLATED )

                            @if($topic->read_right == 1 && Auth::check() || $topic->read_right == 0)
                                <hr/>
                                <div class="markdown-body section " id="emojify">
                                {!! $section->translate_text_html !!}
                                </div>
                            @else
                            <div class="markdown-body" id="emojify">
                                <blockquote><p>本段翻译登录后可阅览</p></blockquote>
                            </div>
                            @endif

                        @else
                                <hr/>
                                <div class="markdown-body section " id="emojify">
                                    {!! $section->original_text_html !!}
                                </div>
                        @endif

                @endforeach
                <div class="meta">
                    <i class="icon fa fa-tags"></i>
                    @foreach($topic->tags as $tag)
                        <a class="ui topic-label" href="{{ route('tags.show', ['id' => $tag->id]) }}"
                           target="_blank">{{ $tag->name }}</a>
                    @endforeach
                </div>
                <div data-lang-excellent="{{ lang('This topic has been mark as Excenllent Topic.') }}"
                     data-lang-wiki="{{ lang('This is a Community Wiki.') }}" class="ribbon-container">
                    @include('topics.partials.ribbon')
                </div>
            </div>
            <div class="appends-container" data-lang-append="{{ lang('Append') }}">
                @foreach ($topic->appends as $index => $append)

                    <div class="appends">
                        <span class="meta">{{ lang('Append') }} {{ $index }} &nbsp;·&nbsp; <abbr
                                    title="{{ $append->created_at }}"
                                    class="timeago">{{ $append->created_at }}</abbr></span>
                        <div class="sep5"></div>
                        <div class="markdown-reply append-content">
                            {!! $append->content !!}
                        </div>
                    </div>

                @endforeach
            </div>
            @include('topics.partials.topic_operate', ['manage_topics' => $currentUser ? ($currentUser->can("manage_topics") && $currentUser->roles->count() <= 5) : false])

        </div>

        @include('topics.partials.show_segment')
        @include('layouts.partials.bottombanner')


    </div>
    @include('translate.partials.show_sidebar_on')

@stop

@section('scripts')

    <script type="text/javascript">

        $(document).ready(function () {
            var $config = {
                title: document.title + ' | from DS #dspstack.com# {{ $topic->user->id != 1 ? '@AllenZhangFive' : '' }} {{ $topic->user->weibo_name ? '@'.$topic->user->weibo_name : '' }}',
                wechatQrcodeTitle: "微信扫一扫：分享", // 微信二维码提示文字
                wechatQrcodeHelper: '<p>微信里点“发现”，扫一下</p><p>二维码便可将本文分享至朋友圈。</p>',
                image: "{{ $cover ? $cover->link : 'https://dspstack.com/uploads/images/201701/29/1/pQimFCe1r5.png' }}",
                sites: ['weibo', 'wechat', 'facebook', 'twitter', 'google', 'qzone', 'qq', 'douban'],
            };

            socialShare('.social-share-cs', $config);

            Config.following_users = @if($currentUser) {!!$currentUser->present()->followingUsersJson()!!} @else [] @endif;
            PHPHub.initAutocompleteAtUser();
        });

        $('#topic-knot-button').click(function () {
            if ({{$topic->status}} != 0 )
            {
                $('#topic-knot-warning').html('该话题已结贴，不能重复结帖');
                $('#topic-knot-warning').removeClass('hidden');
                window.setTimeout(function () {
                    $('#topic-knot-warning').addClass('hidden');
                }, 2000);
                return;
            }
            if ($('#topic-knot-info').hasClass('hidden')) {
                $('#topic-knot-info').removeClass('hidden');
                $('.satisfied-check-item').removeClass('hidden');
            } else {
                $('#topic-knot-info').addClass('hidden');
                $('.satisfied-check-item').addClass('hidden');
            }
        });

        function satisfied_knot(flag) {
//获取checkbox, 并提到后端
            var user_ids = [];
            var replies_ids = [];
//var topic_ids = [];
            $('input[name="checkbox"]:checked').each(function () {
                user_ids.push($(this).val().split('-')[0])
                replies_ids.push($(this).val().split('-')[1])
//topic_ids.push($(this).val().split('-')[2])
            });
            if (flag == 1 && (user_ids.length == 0 || replies_ids.length == 0)) {
                $('#topic-knot-warning').html('您选择的是满意结帖，请在评论区对满意答案打钩');
                $('#topic-knot-warning').removeClass('hidden');
                window.setTimeout(function () {
                    $('#topic-knot-warning').addClass('hidden');
                }, 5000);
                return;
            }
            $.ajax({
                url: "{{url('/topics/knot_homework')}}",
                type: 'POST',
                dataType: 'json',
                data: {
                    user_ids: user_ids,
                    replies_ids: replies_ids,
                    topic_id:{{$topic->id}},
                    flag: flag
                },
                success: function (data) {
                    if (data.status == 1) {
                        $('#topic-knot-success').html('结帖成功,正在刷新页面...');
                        $('#topic-knot-success').removeClass('hidden');
                        setTimeout(function () {
                            window.location.reload(true);
                        }, 2000);
                    }
                },
                error: function (e) {

                }

            });

        }
    </script>
@stop
